package com.ss.android.article.base.ui;

import android.app.Dialog;
import android.content.Context;
import android.text.TextWatcher;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.EditText;
import android.widget.TextView;

import com.ss.android.article.browser.R;
import com.ss.android.common.lib.MobClickCombiner;

import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.ref.WeakReference;

public final class InputUserInfoDialog {
    @Retention(value = RetentionPolicy.SOURCE)
    public @interface MODIFY_TYPE {
    }

    public int a;
    int b;
    int c;
    public String d;
    EditText e;
    TextView f;
    TextView g;
    public View.OnClickListener h;
    WeakReference i;
    TextWatcher j;
    private Dialog k;
    private TextView l;
    private TextView m;
    private TextView n;

    public InputUserInfoDialog(Context arg9, int arg10, int arg11) {
        int v0_2;
        TextView v2;
        View v1;
        View v0_1;
        ViewGroup v6 = null;
        int v5 = 30;
        int v4 = 2;
        int v3 = 10;

        this.a = v3;
        this.b = v4;
        this.c = 0;
        this.j = new u(this);
        this.c = arg10;
        this.i = new WeakReference(arg9);
        LayoutInflater v0 = LayoutInflater.from(arg9);
        if (arg10 == 0) {
            v0_1 = v0.inflate(com.ss.android.article.browser.R.layout.cj, v6);
            this.a = v3;
            this.b = v4;
            v1 = v0_1;
        } else {
            v0_1 = v0.inflate(com.ss.android.article.browser.R.layout.ci, v6);
            if (arg11 == 0) {
                this.a = v5;
                this.b = v3;
                v1 = v0_1;
            } else {
                this.a = v5;
                this.b = 1;
                v1 = v0_1;
            }
        }

        this.m = v1.findViewById(com.ss.android.article.browser.R.id.r6);
        this.e = v1.findViewById(com.ss.android.article.browser.R.id.r7);
        this.f = v1.findViewById(com.ss.android.article.browser.R.id.r9);
        this.g = v1.findViewById(com.ss.android.article.browser.R.id.r8);
        this.n = v1.findViewById(com.ss.android.article.browser.R.id.ra);
        this.f.setEnabled(false);
        this.l = v1.findViewById(com.ss.android.article.browser.R.id.r_);
        if (arg10 == 0) {
            v2 = this.n;
            v0_2 = 0;
        } else {
            TextView v3_1 = this.n;
            if (arg11 == 0) {
                v0_2 = 0;
                v2 = v3_1;
            } else {
                v0_2 = 8;
                v2 = v3_1;
            }
        }

        v2.setVisibility(v0_2);
        this.k = new Dialog(arg9, R.style.k4);
        this.k.setContentView(v1);
        this.k.getWindow().setSoftInputMode(5);
        this.k.getWindow().setLayout(-1, -2);
        this.k.getWindow().setGravity(80);
        this.l.setOnClickListener(new r(this));
        this.f.setOnClickListener(new s(this));
        this.e.addTextChangedListener(this.j);
    }

    public final void a() {
        if (this.k != null) {
            try {
                this.k.getWindow().setGravity(80);
                this.k.setOnShowListener(new t(this));
                this.k.show();
            } catch (Exception v0) {
            }
        }
    }

    static long a(CharSequence arg6) {
        String v3 = arg6.toString().replaceAll("\n", "").trim().replaceAll(" +", " ");
        double v0 = 0;
        int v2;
        for (v2 = 0; v2 < ((CharSequence) v3).length(); ++v2) {
            int v4 = ((CharSequence) v3).charAt(v2);
            if (v4 <= 0 || v4 >= 127) {
                ++v0;
            } else {
                v0 += 0.5;
            }
        }

        return Math.round(v0);
    }

    public final void a(String arg3) {
        if (this.i != null && this.i.get() != null) {
            if (this.c == 0) {
                MobClickCombiner.onEvent((Context) this.i.get(), "account_setting_username", arg3);
            } else if (this.c == 1) {
                MobClickCombiner.onEvent((Context) this.i.get(), "account_setting_signature", arg3);
            }
        }
    }

    public final void b(String arg6) {
        int v4 = 30;
        int v0 = 0;
        if (this.e != null) {
            if (!android.support.design.a.isTextEmpty(arg6)) {
                this.e.setText(((CharSequence) arg6));
                if (this.e.getText() != null && this.e.getText().toString() != null) {
                    v0 = this.e.getText().toString().length();
                }

                this.e.setSelection(v0);
            } else {
                if (this.g == null) {
                    return;
                }

                if (this.c == 0) {
                    this.g.setText(String.format(this.d, Integer.valueOf(v4)));
                    return;
                }

                if (this.c != 1) {
                    return;
                }

                this.g.setText(String.format(this.d, Integer.valueOf(v4)));
            }
        }
    }

    public final String b() {
        String v0 = this.e != null ? this.e.getText().toString() : null;
        return v0;
    }

    public final void c() {
        this.d();
        this.k = null;
    }

    public final void c(String arg2) {
        if (this.m != null && arg2 != null) {
            this.m.setText(((CharSequence) arg2));
        }
    }

    public final void d() {
        try {
            if (this.k == null) {
                return;
            }

            if (!this.k.isShowing()) {
                return;
            }

            this.k.dismiss();
        } catch (Exception v0) {
        }
    }
}

